-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add inlay hints for IndexSignature #56580
Conversation
…ranas/more-inlay-hints
@@ -750,6 +751,17 @@ export function provideInlayHints(context: InlayHintsContext): InlayHint[] { | |||
visitForDisplayParts(node.type); | |||
} | |||
break; | |||
case SyntaxKind.IndexSignature: | |||
Debug.assertNode(node, isIndexSignatureDeclaration); | |||
Debug.assertEqual(node.parameters.length, 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if an assertion is appropriate - what happens if you have something like this?
const x: { []: string }
const y = x;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Specifically, assertions shouldn't assume well-formed code, they should assert invariants of how the compiler constructs the tree. You'd probably be better off with just visitParametersAndTypeParameters
or node.parameters.forEach(visitForDisplayParts)
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get An index signature must have exactly one parameter.ts(1096)
for that code. Also, the parser doesn't create an index signature node for that (the type literal node just has no member
children nodes) so this switch case isn't hit,
That being said, I also wasn't so enthusiastic about using the assert but wasn't sure about alternatives. Your suggestion is better though since this is a user error and we already report diagnostics to the user elsewhere.
I think this should be represented in the types though so we can enforce the invariant. Can we just add something like:
export interface IndexSignatureDeclaration extends SignatureDeclarationBase, ...
{
...
readonly parameters: [ParameterDeclaration] & NodeArray<ParameterDeclaration>;
}
It's probably not that easy since this is a public API and would be breaking.
Fixes #56559